//
//  SINAStuApproveUserNameViewController.m
//  sinashebao
//
//  Created by  androidlongs on 2018/1/26.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "SINAStuApproveStudentViewController.h"
#import "SINACircularBeadUtils.h"
#import "SINAStuApproveSelectSchoolViewController.h"
#import "SINAStuApproveSchoolClassViewController.h"
#import "SINAStuApproveSchoolCountController.h"

@interface SINAStuApproveStudentViewController ()
@property(strong,nonatomic) UILabel *studentSchoolUILabel;
@end

@implementation SINAStuApproveStudentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [super initBackItem];
    SINAUserModel *userModel = [[SINACommonUserHelper share] getUserModel];
    if (userModel!=nil) {
        if ([userModel.identitys integerValue]==1) {
            self.navigationItem.title=@"学生认证";
        } else {
            self.navigationItem.title=@"老师认证";
        }
    } else {
        self.navigationItem.title=@"学生认证";
    }
    
    [self initViewFunction];
}
-(void) initViewFunction{
    UIScrollView *mainScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, mainW, mainH-49)];
    mainScrollView.contentSize=CGSizeMake(mainW, mainH+10);
    [self.view addSubview:mainScrollView];
    [self.view setBackgroundColor:[UIColor colorWithHexString:@"#eeeeee"]];
    
    UIView *itemView1 =[[UIScrollView alloc]initWithFrame:CGRectMake(0, 22, mainW, 48)];
    [itemView1 setBackgroundColor:[UIColor whiteColor]];
    [mainScrollView addSubview:itemView1];
    
    
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetHeight(itemView1.frame)/2-10, mainW-30, 21)];
    titleLabel.text=@"学校";
    [titleLabel setFont:[UIFont systemFontOfSize:16]];
    titleLabel.textColor=[UIColor colorWithHexString:@"#212121"];
    
    [itemView1 addSubview:titleLabel];
    
    UILabel *inputTextField = [[UILabel alloc]initWithFrame:CGRectMake(55, CGRectGetHeight(itemView1.frame)/2-17, mainW-45, 36)];
    
    [inputTextField setFont:[UIFont systemFontOfSize:16]];
    inputTextField.text=@"请选择你所在的学校";
    inputTextField.textColor=[UIColor colorWithHexString:@"#878787"];
    
    self.studentSchoolUILabel =inputTextField;
    
    [itemView1 addSubview:inputTextField];
    
    
    UILabel *nextLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(itemView1.frame)+48, mainW-30, 42)];
    nextLabel.text=@"下一步";
    nextLabel.textAlignment=NSTextAlignmentCenter;
    [nextLabel setFont:[UIFont systemFontOfSize:20]];
    nextLabel.textColor=[UIColor colorWithHexString:@"#ffffff"];
    [SINACircularBeadUtils makeCircularBead:1 andView:nextLabel andIsSetBackground:YES];
    [mainScrollView addSubview:nextLabel];
    
    WeakSelf;
    //下一步
    [[SINAUiviewClickLiserner alloc]viewClickFunction:nextLabel andWithBlick:^(UIView *view) {
        [weakSelf nextFunction];
    }];
    //选择学校
    [[SINAUiviewClickLiserner alloc]viewClickFunction:itemView1 andWithBlick:^(UIView *view) {
        SINAStuApproveSelectSchoolViewController *studentController=[[SINAStuApproveSelectSchoolViewController alloc]init];
        studentController.currentSchooleModel = weakSelf.currentSchooleModel;
        [weakSelf.navigationController pushViewController:studentController animated:YES];
    }];
    
}
-(void) nextFunction{
    NSString *studentName = self.studentSchoolUILabel.text;
    if (studentName==nil||studentName.length<1||[studentName isEqualToString:@"请选择你所在的学校"]) {
        
        WISAlertView *alertView =
        [[WISAlertView alloc]initWithTitle:@"提示" message:@"请输入你所在学校" sureBtn:@"确定" cancleBtn:nil];
        [alertView showXLAlertView];
        
        return;
    }
    
    SINAUserModel *userModel = [[SINACommonUserHelper share] getUserModel];
    if (userModel!=nil) {
        if ([userModel.identitys integerValue]==1) {
            SINAStuApproveSchoolClassViewController *studentController=[[SINAStuApproveSchoolClassViewController alloc]init];
            studentController.studentName = self.studentName;
            studentController.currentSchooleModel=self.currentSchooleModel;
            [self.navigationController pushViewController:studentController animated:YES];
        } else {
            
            SINAStuApproveSchoolCountController *studentController=[[SINAStuApproveSchoolCountController alloc]init];
            studentController.studentName = self.studentName;
            studentController.currentSchooleModel = self.currentSchooleModel;
            
            [self.navigationController pushViewController:studentController animated:YES];
        }
    } else {
        WISAlertView *alertView =
        [[WISAlertView alloc]initWithTitle:@"提示" message:@"信息不全 重新登录" sureBtn:@"确定" cancleBtn:nil];
        [alertView showXLAlertView];
    }
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   
}

-(void)viewWillAppear:(BOOL)animated{
    if (self.currentSchooleModel!=nil) {
        self.studentSchoolUILabel.text=self.currentSchooleModel.schoolName;
    }
}

@end
